﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
namespace DataAccess_Layer
{
    
    public class ChungLoaiDAC
    {
        public static DataClasses_RetailerDataContext context = DataAccessHelper.DB;
        public static List<ChungloaiSPDTO> getALL()
        {
            List<ChungloaiSPDTO> cats = null;

            DataAccessHelper helper = null;
            SqlDataReader rdr = null;
            try
            {
                helper = new DataAccessHelper();

                rdr = helper.excuteSP("SP_Get_All_ChungLoaiSP");

                if (rdr.HasRows)
                {
                    cats = new List<ChungloaiSPDTO>();
                    while (rdr.Read())
                    {
                        ChungloaiSPDTO cat = createChungLoai(ref rdr);
                        cats.Add(cat);
                    }
                }
            }
            finally
            {
                helper.close();
                rdr.Close();
            }

            return cats;
        }
        private static ChungloaiSPDTO createChungLoai(ref SqlDataReader rdr)
        {
            ChungloaiSPDTO cat = new ChungloaiSPDTO();
            cat.MaSP = (long)rdr["ID"];
            cat.TenSP = (string)rdr["Ten"];
           
            return cat;
        }
        public static void Insert(ChungLoaiSP cl)
        {
            context.ChungLoaiSPs.InsertOnSubmit(cl);
            DataAccessHelper.Save();

        }
    }
}
